<?php
//including header.php 
include '../../include/header.php';
//including page.php (It is a class which contain functions)
include '../../libraries/page.php';
//created object for page.php
$page = new page();
session_start();

if (!$_SESSION['admin_username']) {
    header("location:../../admin/login.php");
}

if ($_GET['q'] == 'logout') {
    $page->admin_logout();
    header("location:login.php");
}

if ($_SERVER["REQUEST_METHOD"] == "POST") {

    if ($_POST['chkDel'] == "") {
        $msg = $message[8];
    } else {
        $result = $page->delete("userid", "users", $_POST['chkDel']);
        if ($result) {
            $msg = $message[2];
        } else {
            $msg = $message[0];
        }
    }
}
?>
<!-------------------------------------Navbar---------------------------------->
<div class="navbar">
    <div class="navbar-inner">
        <ul class="nav">
            <li><a href="index"><b style="font-size: 18px;margin-left: 30px">Admin</b></a></li>
        <!----<li><a href="groups">Groups</a></li>
            <li><a href="../products/products">Products</a></li>
            <li><a href="../../suppliers/suppliers">Suppliers</a></li>--->
        </ul>
        <a class="brand" href="../../index"  id="right_title"><b style="color:#333;">Inventory</b></a>
        <i class="icon-home" id ="right"></i>
    </div>
</div>
<div style="float:right; margin-right:30px"> <a href="?q=logout">Log out</a></div>
<!--------------------------------------content-------------------------------->
<div style="width:960px; margin-left: auto;margin-right: auto; margin-top: 100px;">
    <span><strong style="font-size:22px;">Groups</strong>
      <!---  <a onclick="javascript:checkAll('frmMain', false);" href="javascript:void();" style="float:right">uncheck all</a>
        <a onclick="javascript:checkAll('frmMain', true);" href="javascript:void();" style="float:right; margin-right: 20px;">check all</a></span>-->
		 <a href="javascript:reserveCheck('chkDel[]')" style="float:right">Invert Select</a>
		 <a href="javascript:allCheck('chkDel[]',false)" style="float:right; margin-right: 20px;">Select None</a> 
		 <a href="javascript:allCheck('chkDel[]',true)" style="float:right; margin-right: 20px;">Select All</a></span>
</div>
<br />

<!------------------------------Header Table------------------------------------->
<!----<table class="table table-striped" style="width:500px; margin-left: 12%;margin-top: 50px;">
    <tr><th  colspan="2">Part No</th><th>Part Name</th></tr>

    <tr><th>Old NO</th><td>897082</td><td>Honda brake kit</td></tr>
    <tr><th>New NO</th><td>978456</td><td></td></tr>
</table>------->


<!------------------------------Form------------------------------------->
<form name="yourname"" action="" method="post" OnSubmit="return onDelete();">

    <!------------------------------Details Table------------------------------------->
    <table class="table table-striped" style="width:960px; margin-left: auto;margin-right: auto;">
        <tr>
            <th></th>
            <th>SL NO</th>
            <th>Name</th>
            <th>Password</th>
            <th>Email</th>
            <th>Random code</th>
            <th>Status</th>
             <th>Edit</th>
        </tr>
 
        <?
        //php code to get the data from groups table 
        $users = mysql_query("select * from users");
        $id = 0;
        while ($users_data = mysql_fetch_array($users)) {

            $users_id = $users_data['userid'];
            $name = $users_data['username'];
            $password = $users_data['password'];
            $email = $users_data['email'];
            $randomcode = $users_data['randomcode'];
            $active = $users_data['active'];
            $id++;
            ?>
			
            <!-------------------------Dynamic row to display from database--------------------->
            <tr>
                <td><input type="checkbox" name="chkDel[]" id="choice" value="<?=$users_id; ?>"></td>
                <td><?=$id; ?></td>
                <td><a href="group_update?id=<?=$users_id; ?>"><?=$name; ?></a></td>
                <td><?=$password; ?></td>
                <td><?=$email; ?></td>
                <td><?=$randomcode; ?></td>
                <td><?=$active; ?></td>
                <td><a href="user_update?id=<?=$users_id; ?>">Edit</a></td>
            </tr>

            <?
            // Closing the loop
        }
        ?>

    </table>

    <!----------------------------------Display the result message of deletion--------------------->
    <div  align="center"><? echo $msg; ?></div>

    <!----------------------------CRUD Buttons-------------------------------------->
    <div align="center">
        <a href="user_add"><button class="btn btn-primary" type="button">Add</button></a>
        <!-----<button class="btn btn-inverse" type="button">Update</button>----->
        <button class="btn btn-danger" type="submit">Delete</button>
    </div>
</form>
<?php
//including footer.php
include '../../include/footer.php';
?>
